﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TCHSHue.DAL;

namespace TCHSHue.BLL
{
    public class TheLoaiBLL
    {
        internal static List<TheLoai> getList()
        {
            using (QLHSHueDataContext data = new QLHSHueDataContext())
            {
                var ls = from e in data.TheLoais
                         orderby e.tenTheLoai ascending
                         select e;
                return ls.ToList();
            }
        }

        internal static TheLoai getTheLoai(int maTheLoai)
        {
            using (QLHSHueDataContext data = new QLHSHueDataContext())
            {
                var tl = (from e in data.TheLoais
                          where e.maTheLoai == maTheLoai
                          select e).SingleOrDefault();
                return tl;
            }
        }

        internal static bool createBaiVietNoiBat(int maTheLoai, Guid maBaiViet)
        {
            using (QLHSHueDataContext data = new QLHSHueDataContext())
            {
                var tl = (from e in data.TheLoais
                          where e.maTheLoai == maTheLoai
                          select e).SingleOrDefault();
                if (tl != null)
                {
                    tl.baiVietNoiBat = maBaiViet;
                    data.SubmitChanges();
                    return true;
                }
                return false;
            }
        }

        internal static string getIdBaiVietNoiBat(int maTheLoai)
        {
            using (QLHSHueDataContext data = new QLHSHueDataContext())
            {
                var tl = (from e in data.TheLoais
                          where e.maTheLoai == maTheLoai
                          select e).SingleOrDefault();
                if (tl != null)
                {
                    return tl.baiVietNoiBat.HasValue ? tl.baiVietNoiBat.Value.ToString() : null;
                }
                else
                    return null;
            }
        }
    }
}